package edu.luc.etl.jbunit.tl;

/**
 * The formula <code>previous p</code> specifies
 * that <code>p</code> must have been true in the
 * time unit immediately preceding the current one.
 */

public class Previous<T> extends Expr<T> {

  private Expr<T> p;
  private boolean prev=false;

  public Previous(Expr<T> p) {
    this.p = p;
  }

  public Previous(T p) {
    this(new Leaf<T>(p));
  }

  public Previous<T> clone() {
    Previous<T> result = (Previous<T>) super.clone();
    result.p =  p.clone();
    return result;
  }

  public void reset () { prev = false; p.reset(); }

  public void tick () { evaluated = false; p.tick(); }

  boolean ev () {
    boolean pp = prev;
    prev = p.valuate();

    val = pp;
    return val;
  }

  void accept(Visitor<T> v) {
    v.visitPrevious(this);
    p.accept(v);
  }
}

